
public class Trycasting//本类讲解了父类引用指向子类对象
//本类中info方法的调用,是各自类的引用,调用各自的info方法
{
	public static void main(String args[]){
		Students s1 = new Students("qdu");
		SEfaculty mf = new SEfaculty("wang",20,"qdu");
		Graduated gd = new Graduated("lee", "中南海", "qdu");

		s1.info();
		mf.info();
		gd.info();

		Students s2 = new Graduated("Broose Lee","Hollywood","少林");//父类引用指向子类对象
		System.out.println(s2.school);//父类引用访问子类对象中的父类成员
		//System.out.println(s2.name + s2.dept);//父类引用访问子类对象中的子类成员,出错,需要强制转型

		s1 = mf;//子类饮用赋值给父类引用
		System.out.println(s1.school);//访问父类成员
		//System.out.println(s1.name);//访问子类成员,出错,需要强制转型

		Graduated gs2 = (Graduated)s2; //父类引用赋值给子类引用需要强制转
		//gs2.school = "武当";
		//System.out.println(s2.school);


		System.out.println(s1 instanceof Students);
		System.out.println(mf instanceof SEfaculty);
		//System.out.println(mf instanceof Graduated);
		System.out.println(mf instanceof Students);
		System.out.println(s1 instanceof SEfaculty);
	}
}